package com.goods.business.controller;

import com.goods.business.service.ProductService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author jiaoyanlin
 * @Date 2021/11/8 21:33
 * @Description ProductController
 */
@RestController
@RequestMapping("/business/product")
public class ProductController {
    @Autowired
    ProductService productService;
    //?pageNum=1&pageSize=6&name=&categoryId=&supplier=&status=0
@GetMapping("/findProductList")
public ResponseBean<PageVO<ProductVO>> findProductList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize",defaultValue = "6") Integer pageSize,
                                                       @RequestParam Map<String,Object> queryMap){
    System.out.println(queryMap);
    PageVO<ProductVO> pageVo = productService.findProductList(queryMap);
    return ResponseBean.success(pageVo);
}
    @GetMapping("/findProducts")
    public ResponseBean<PageVO<ProductVO>> findProducts( @RequestParam Map<String,Object> queryMap){
        PageVO<ProductVO> pageVo = productService.findProductList(queryMap);
        return ResponseBean.success(pageVo);
    }


//edit/37
    @GetMapping("/edit/{id}")
   public ResponseBean edit(@PathVariable String id){

     ProductVO productVO =  productService.edit(id);
    return ResponseBean.success(productVO);
    }

    ///update/37
    @PutMapping("/update/{id}")
    public ResponseBean update(@RequestBody ProductVO productVo,@PathVariable Long id){
      productService.update(productVo,id);
    return ResponseBean.success();
    }

    ///back/51
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        productService.back(id);
        return ResponseBean.success();
    }

    //
    @PostMapping("/add")
    public ResponseBean add(@RequestParam Map<String,Object> map){
        System.out.println(map);
    productService.add(map);
    return ResponseBean.success();
    }

    //remove/51  回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        productService.remove(id);
        return ResponseBean.success();
    }
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(Long id){
        productService.delete(id);
        return ResponseBean.success();

    }
   //
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id){
        productService.publish(id);
        return ResponseBean.success();
    }
    //库存相关
    @GetMapping("/findProductStocks")
    public ResponseBean<PageVO<ProductStockVO>> findProductStocks(@RequestParam Map<String,Object> map){
        PageVO<ProductStockVO> pageVO = productService.findProductStocks(map);
        return ResponseBean.success(pageVO);
    }
    @GetMapping("/findAllStocks")
    public ResponseBean<PageVO<ProductStockVO>> findAllStocks(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                              @RequestParam(value = "pageSize",defaultValue = "9") Integer pageSize){
        PageVO<ProductStockVO> pageVO = productService.findAllStocks(pageNum,pageSize);
        return ResponseBean.success(pageVO);
    }
}
